import java.io.*;
import java.net.*;
public class Reciever{
	
	public static String host = "localhost" ;
	public static int port = 8000 ;
	public static int stopWay = 1 ;

	public static int STATE_NATURE = 1 ;
	public static int STATE_SUPPEND = 2 ;
	public static int STATE_SOCKET = 3 ;
	public static int STATE_OUTPUT = 4 ;

	ServerSocket server = null ;
	Socket socket = null ;

	public Reciever() throws Exception{
		server = new ServerSocket(port);	
		System.out.println("start...");
		
		socket = server.accept();
		System.out.println("new connect:" + socket.getInetAddress() + ":" + socket.getPort());

		BufferedReader reader = getReader(socket);

		for(int i = 0 ; i < 20 ; i ++){
			
			String msg = reader.readLine();
			System.out.println(msg);
			
			Thread.sleep(1000);


		}
		
		if(socket.isConnected() && !socket.isClosed()){
			socket.close();
		}
		
		server.close();

	}

	public BufferedReader getReader(Socket socket) throws Exception{
		InputStream in = socket.getInputStream();
		return new BufferedReader(new InputStreamReader(in));
	}


	public static void main(String[] args) throws Exception{
		new Reciever();		
	}
}
